package org.budo.java.agent;

import java.net.URL;
import java.net.URLClassLoader;

import org.budo.java.agent.transformer.javassist.JavassistClassFileTransformer;
import org.budo.support.lang.util.IoUtil;
import org.budo.support.lang.util.ReflectUtil;

import javassist.ClassPool;
import javassist.CtClass;

/**
 * @author lmw
 */
public class Main {
    @SuppressWarnings("deprecation")
    public static void main(String[] args) throws Throwable {
        String typeName = BudoUserServiceImpl.class.getName();

        ClassPool classPool = ClassPool.getDefault();
        CtClass typeCtClass = classPool.get(typeName);
        CtClass ctClass = new JavassistClassFileTransformer().transform(typeCtClass);
        IoUtil.write(ctClass.toBytecode(), IoUtil.fileOutputStream("/aaaaaaaaaaaaaaa/BudoUserServiceImpl.class"));

        Object userService = ctClass.toClass(new URLClassLoader(new URL[0])).newInstance();

        ReflectUtil.getMethod(userService.getClass(), "hello", new Class[0]).invoke(userService);
        ReflectUtil.getMethod(userService.getClass(), "hello", new Class[0]).invoke(userService);
    }
}